package com.zxl.gtion.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zxl.gtion.dao.ArticleInfoDao;
import com.zxl.gtion.dto.ArticleDTO;
import com.zxl.gtion.entity.ArticleContent;
import com.zxl.gtion.entity.ArticleInfo;
import com.zxl.gtion.service.ArticleContentService;
import com.zxl.gtion.service.ArticleInfoService;
import com.zxl.gtion.vo.ArticleInfoVO;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * (ArticleInfo)表服务实现类
 *
 * @author 
 * @since 2024-03-06 16:42:53
 */
@Service("articleInfoService")
@Slf4j
@RequiredArgsConstructor
public class ArticleInfoServiceImpl extends ServiceImpl<ArticleInfoDao, ArticleInfo> implements ArticleInfoService {

    private final ArticleContentService articleContentService;

    @Override
    public ArticleInfoVO selectInfoById(Integer id) {
        // 根据id获取文章信息， 然后用BeanUtil工具类转换称ArticleInfoVO方便后期数据展示
        ArticleInfoVO articleInfoVO = BeanUtil.copyProperties(this.getById(id), ArticleInfoVO.class);
        ArticleContent articleContent = articleContentService.lambdaQuery().eq(ArticleContent::getArticleId, id).one();
        if (articleContent != null) {
            articleInfoVO.setContent(articleContent.getContent());
            articleInfoVO.setArticleContent(articleContent);
        }
        return articleInfoVO;
    }


}

